package main

import "fmt"

/*
	嵌套匿名结构体
*/

type User struct {
	UserName string
	Password string
	Address  //表示User结构体嵌套Address结构体
}

type Address struct {
	Name  string
	Phone string
	City  string
}

func main() {
	var u2 User
	u2.UserName = "张三"
	u2.Password = "456789"
	u2.Address.Name = "张先生"
	u2.Address.Phone = "15323132132"
	u2.Address.City = "深圳市福田区"

	u2.City = "上海" //当访问结构体成员时会先在结构体中查找该字段，找不到再去匿名结构体中查找

	fmt.Printf("%#v\n", u2) //main.User{UserName:"张三", Password:"456789", Address:main.Address{Name:"张先生", Phone:"15323132132", City:"上海"}}

	fmt.Println(u2.Phone)
	fmt.Println(u2.Address.Phone)
}
